<?php

namespace App\Api\Dao;

use App\Models\TongUserMonthMoney;

class UserMonthMoneyDao
{
    /**
     * @param $data
     * @return \Illuminate\Database\Eloquent\Builder
     */
    function getBuildQuery($data)
    {
        // TODO: Implement getBuildQuery() method.
        $query = TongUserMonthMoney::query();
        if(checkIsHasField($data,'id')){
            $query->where('id',$data['id']);
        }
        if(checkIsHasField($data,'u_id')){
            $query->where('u_id',$data['u_id']);
        }
        if(checkIsHasField($data,'p_id')){
            $query->where('p_id',$data['p_id']);
        }
        //流水的到账状态 1：已到账 2 ：未到账
        if(checkIsHasField($data,'start_time')){
            $query->whereDate('created_at','>=',$data['start_time']);
        }

        if(checkIsHasField($data,'end_time')){
            $query->whereDate('created_at','<=',$data['end_time']);
        }

        $query->orderBy('id','desc');

        return $query;
    }

    /**
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|void
     */
    public function getMonthMoney($data){
        return $this->getBuildQuery($data)->with('uInfo')->get();
    }
}
